//
//  StackTests.m
//  OR_1
//
//  Created by Luboš Kulič on 8/18/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "StackTests.h"
#import "Stack.h"
#import "Random.h"


@implementation StackTests

-(void) setUp {
	stack = [[Stack stack] retain];
}

-(void) tearDown {
	[stack autorelease];	
}

-(void)testInitStack{
	
	STAssertNotNil(stack, @"Stack is null");
	
}


-(void)testPush {
	NSString * str1 = @"Test1", *str2 = @"Test2", *str3 = @"Test3";
	[stack push:str1];
	[stack push:str2];
	[stack push:str3];
	
	NSLog(@"Stack: %@", stack);
}

-(void)testPop{
	NSString * str1 = @"Test1", *str2 = @"Test2", *str3 = @"Test3";
	[stack push:str1];
	[stack push:str2];
	[stack push:str3];
	NSString *ret = [[stack pop] retain];
	STAssertEquals(str3, ret, @"Popped string differs from Test3");
	[ret autorelease];
	
	[stack push:str1];
	ret = [[stack pop] retain];
	STAssertEquals(str1, ret, @"Popped string differs from Test1");
	[ret autorelease];
	 
	
	NSLog(@"Stack: %@", stack);
}


/*
-(void)testPushPopStressTest{
	
	
	int stackSize = 0;
	for (int i = 0; i < 100000; ++i) {
		//	randomly either push or pop a string "TestN" where N means current size of the stack
		//	i.e. when pushing, create the string, when popping, check correct string has been popped
		//	when the stack is emty, can only push
		

		
		if(stackSize > 0 && ([Random randomBool])) {

			// pop
			NSString *str = [[stack pop] retain];
			
			NSString *testStr = [@"Test" stringByAppendingString:[NSString stringWithFormat:@"%d", --stackSize]];
			
			STAssertNotNil(str, @"Popped string is nil" );
			STAssertTrue( [testStr isEqualToString:str], @"Wrong string popped %@, should be %@", str, testStr);
			[str autorelease];
			
		} 
		else {
			// push
			[stack push:[@"Test" stringByAppendingString:[NSString stringWithFormat:@"%d", stackSize++]]];
			
		}
		//NSLog(@"Stack: %@", stack);

		
	}
 
	
}

*/

@end
